#!/usr/bin/env bash

source="src/"

a2psFile(){
local -a fileList=$@
#local -a fichier=$1
#local -a fileName=$(basename $fichier java)
#local -a module=$(echo $fileName | sed "s|/|.|g")
a2ps -1 -P pdf --prologue=color --tabsize 4 --pretty-print Java --highlight-level heavy -X ISO-8859-1 --header="" --left-title="" -o ./poa.ps $fileList
}

parser(){
local -a content=$@
local -a fileList
local -i counter=0
for item in ${content[@]}
do
	if [ ! -e "$item" ]; then
		echo "$item n'existe pas"
	elif [ -f "$item" ]; then
		if test "${item##*.}" = "java"; then
			echo "$item est un fichier java"
			fileList[$counter]=$item
			((counter++))
		fi
	fi
done
a2psFile "${fileList[@]}"
}

######### Main ############
declare -a content=$(tree -fi $source)
parser $content
